package com.example.maggie.meizinote.mvp.ui.adapter;

import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.maggie.meizinote.R;
import com.example.maggie.meizinote.app.MApp;
import com.example.maggie.meizinote.app.bean.ClassifyBean;
import com.example.maggie.meizinote.app.bean.note_item;

import java.util.List;

/**
 * Created by addis on 2018/4/21.
 */
public class NoteListAdapter extends BaseQuickAdapter<note_item, BaseViewHolder> {
    private List<ClassifyBean> object;

    public NoteListAdapter() {
        super(R.layout.item_note);
    }

    public void setClassifyData(List<ClassifyBean> object) {
        this.object = object;
        notifyDataSetChanged();
    }

    public String getNoteClassifyName(note_item item) {
        if (object != null)
            for (int i = 1; i < object.size(); i++) {
                if (object.get(i).getObjectId().equals(item.getClassify_id()))
                    return object.get(i).getTitle();
            }
        return "默认目录";
    }

    @Override
    protected void convert(BaseViewHolder helper, note_item item) {
        helper.setText(R.id.title, item.getNote_title());
        if (item.getClassify_id() == null)
            helper.setText(R.id.classify, "所属目录：默认目录");
        else
            helper.setText(R.id.classify, "所属目录：" + getNoteClassifyName(item));
        helper.setText(R.id.time, "上次更新时间：" + item.getUpdatedAt());
        if (MApp.isNight) {
            helper.getView(R.id.list_item).setBackgroundColor(mContext.getResources().getColor(R.color.night_item_bg_color));
            ((TextView) helper.getView(R.id.title)).setTextColor(mContext.getResources().getColor(R.color.night_txt_color));
            ((TextView) helper.getView(R.id.time)).setTextColor(mContext.getResources().getColor(R.color.night_txt_color));
            ((TextView) helper.getView(R.id.classify)).setTextColor(mContext.getResources().getColor(R.color.night_txt_color));
        } else {
            helper.getView(R.id.list_item).setBackgroundColor(mContext.getResources().getColor(R.color.white));
            ((TextView) helper.getView(R.id.title)).setTextColor(mContext.getResources().getColor(R.color.color_3));
            ((TextView) helper.getView(R.id.time)).setTextColor(mContext.getResources().getColor(R.color.color_8));
            ((TextView) helper.getView(R.id.classify)).setTextColor(mContext.getResources().getColor(R.color.color_8));
        }
    }
}
